package edu.sjb.map;

import edu.sjb.AppLauncher;
import edu.sjb.map.prizes.Prize;
import edu.sjb.map.prizes.PrizeQueue;

public class MapBrick implements LogicMapElement {
	
	public static final String ELEMENT_NAME = "Brick";
	
	private boolean questionMark;
	private boolean solid;
	private boolean opaque;
	private PrizeQueue prizes;

	public MapBrick(boolean q, boolean s, boolean o, PrizeQueue pq) {
		setQuestionMark(q);
		setSolid(s);
		setOpaque(o);
		setPrizes(pq);
	}
	
	@Override
	public String getName() {
		return ELEMENT_NAME;
	}

	public boolean isQuestionMark() {
		return questionMark;
	}

	public void setQuestionMark(boolean questionMark) {
		this.questionMark = questionMark;
	}

	public boolean isSolid() {
		return solid;
	}

	public void setSolid(boolean solid) {
		this.solid = solid;
	}

	public boolean isOpaque() {
		return opaque;
	}

	public void setOpaque(boolean opaque) {
		this.opaque = opaque;
	}

	public PrizeQueue getPrizes() {
		return prizes;
	}

	public void setPrizes(PrizeQueue prizes) {
		this.prizes = prizes;
	}
	
	public void hit(int x, int y) {
		if (opaque) {
			if (questionMark) {
				if (!prizes.isEmpty()) {
					Prize p = prizes.removeTop();
					AppLauncher
							.GUI()
							.map()
							.setElementAt(
									x,
									y,
									GenericMapElementFactory
											.brick(MapLoader.MASK_IS_SOLID));
					AppLauncher
							.GUI()
							.map()
							.setElementAt(x, y - 1,
									GenericMapElementFactory.releasedPrize(p));
				}
			}
			else {
				if(!solid) {
					AppLauncher.GUI().map().setElementAt(
							x,
							y,
							GenericMapElementFactory.emptySpace());
				}
			}
		}
		else {
			if(solid) {
				if (!prizes.isEmpty()) {
					Prize p = prizes.removeTop();
					AppLauncher
							.GUI()
							.map()
							.setElementAt(
									x,
									y,
									GenericMapElementFactory
											.brick(MapLoader.MASK_IS_SOLID));
					AppLauncher
							.GUI()
							.map()
							.setElementAt(x, y - 1,
									GenericMapElementFactory.releasedPrize(p));
				}
			}
		}
	}
}
